
<div style="padding: 15px;">
    <table id="projectTable" lay-filter="optionTable"></table>
</div>
<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
    layui.use('table', function() {
        let table = layui.table;
        table.render({
            elem: '#projectTable'
            , url: '/option/list'
            , cols: [
                [
                    {field: 'projectId', title: '项目编号',align: 'center'}
                    ,{field: 'projectName', title: '项目名称', templet:function (res){
                        return res.projectEntity.projectName;},align: 'center'}
                    ,{field: 'staffId', title: '提出人编号',align: 'center'}
                    ,{field: 'content', title: '意见内容',align: 'center'}
                    , {title: '操作', align: 'center', width: 200, toolbar: '#bar'}
                ]
            ]
            , page: true
        });

        table.on('tool(optionTable)', function (obj) { //tool是工具条事件名，参数是table原始容器的lay-filter属性值
            let layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'edit') {
                layer.open({
                    type: 2,
                    title: '更新项目信息',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['893px', '600px'],
                    content: '/router/option/'+obj.data.projectId,
                });
            }
            if (layEvent === 'del'){
                layer.confirm('确定删除？', function (index) {
                    layer.close(index);
                    layer.load(1);
                    //向服务器发送删除文章请求
                    layui.jquery.ajax({
                        url:"option/delete",
                        contentType: "application/json;charset=utf-8",
                        method:"POST",
                        data: JSON.stringify({"optionId":obj.data.optionId}),
                        success:function (result) {
                            layer.closeAll('loading');//关闭loading图标
                            layer.msg("删除成功", {icon: 1});
                            obj.del(); //删除表格对应行并更新缓存
                        }
                    })
                });
            }
        });

    });
</script>